﻿using Glue;
using Glue.Converters;
using Xunit;

namespace GlueTests.Converters
{
    public class CustomConverterTest
    {

        [Fact]
        public void Should_work_with_two_functions()
        {
            var converter = new QuickConverter<int,bool>(fromInt=>fromInt!=0, fromBool=>0);
            Assert.Equal(false,converter.MapTowardsRight(0));
            Assert.Equal(true, converter.MapTowardsRight(13));
            Assert.Equal(0,converter.MapTowardsLeft(true));
            Assert.Equal(0, converter.MapTowardsLeft(false));
        }

        [Fact]
        public void Should_work_with_one_function_the_correct_way()
        {
            var converter = new QuickConverter<int, bool>(fromInt => fromInt != 0);
            Assert.Equal(false, converter.MapTowardsRight(0));
            Assert.Equal(true, converter.MapTowardsRight(13));
        }

        [Fact]
        public void Should_throw_meaningful_exception_with_one_function_the_wrong_way()
        {
            var converter = new QuickConverter<int, bool>(fromInt => fromInt != 0);
            Assert.Throws( typeof(GlueException),()=> converter.MapTowardsLeft(true));
            
        }
    }
}
